package gsoc.ogsadai.model.diagram.providers;

import gsoc.ogsadai.model.ModelPackage;
import gsoc.ogsadai.model.diagram.part.RequestDiagramEditorPlugin;

import java.util.HashSet;
import java.util.IdentityHashMap;
import java.util.Map;
import java.util.Set;

import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EClassifier;
import org.eclipse.emf.ecore.ENamedElement;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.gmf.runtime.emf.type.core.ElementTypeRegistry;
import org.eclipse.gmf.runtime.emf.type.core.IElementType;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.resource.ImageRegistry;
import org.eclipse.swt.graphics.Image;

/**
 * @generated
 */
public class RequestElementTypes extends ElementInitializers {

	/**
	 * @generated
	 */
	private RequestElementTypes() {
	}

	/**
	 * @generated
	 */
	private static Map elements;

	/**
	 * @generated
	 */
	private static ImageRegistry imageRegistry;

	/**
	 * @generated
	 */
	private static Set KNOWN_ELEMENT_TYPES;

	/**
	 * @generated
	 */
	public static final IElementType WorkflowType_79 = getElementType("gsoc.ogsadai.diagram.WorkflowType_79"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType PipelineType_1001 = getElementType("gsoc.ogsadai.diagram.PipelineType_1001"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType ParallelType_1002 = getElementType("gsoc.ogsadai.diagram.ParallelType_1002"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType SequenceType_1003 = getElementType("gsoc.ogsadai.diagram.SequenceType_1003"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType ActivityType_2001 = getElementType("gsoc.ogsadai.diagram.ActivityType_2001"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType InputsType_2002 = getElementType("gsoc.ogsadai.diagram.InputsType_2002"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType InputType_2003 = getElementType("gsoc.ogsadai.diagram.InputType_2003"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType InputStreamType_2004 = getElementType("gsoc.ogsadai.diagram.InputStreamType_2004"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType DataType_2005 = getElementType("gsoc.ogsadai.diagram.DataType_2005"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType OutputsType_2006 = getElementType("gsoc.ogsadai.diagram.OutputsType_2006"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType OutputStreamType_2007 = getElementType("gsoc.ogsadai.diagram.OutputStreamType_2007"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType WorkflowType_2008 = getElementType("gsoc.ogsadai.diagram.WorkflowType_2008"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType PipelineType_2009 = getElementType("gsoc.ogsadai.diagram.PipelineType_2009"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType ParallelType_2010 = getElementType("gsoc.ogsadai.diagram.ParallelType_2010"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType SequenceType_2011 = getElementType("gsoc.ogsadai.diagram.SequenceType_2011"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType WorkflowType_2012 = getElementType("gsoc.ogsadai.diagram.WorkflowType_2012"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType OutputStreamTypePipe_3001 = getElementType("gsoc.ogsadai.diagram.OutputStreamTypePipe_3001"); //$NON-NLS-1$

	/**
	 * @generated
	 */
	private static ImageRegistry getImageRegistry() {
		if (imageRegistry == null) {
			imageRegistry = new ImageRegistry();
		}
		return imageRegistry;
	}

	/**
	 * @generated
	 */
	private static String getImageRegistryKey(ENamedElement element) {
		return element.getName();
	}

	/**
	 * @generated
	 */
	private static ImageDescriptor getProvidedImageDescriptor(
			ENamedElement element) {
		if (element instanceof EStructuralFeature) {
			EStructuralFeature feature = ((EStructuralFeature) element);
			EClass eContainingClass = feature.getEContainingClass();
			EClassifier eType = feature.getEType();
			if (eContainingClass != null && !eContainingClass.isAbstract()) {
				element = eContainingClass;
			} else if (eType instanceof EClass
					&& !((EClass) eType).isAbstract()) {
				element = eType;
			}
		}
		if (element instanceof EClass) {
			EClass eClass = (EClass) element;
			if (!eClass.isAbstract()) {
				return RequestDiagramEditorPlugin.getInstance()
						.getItemImageDescriptor(
								eClass.getEPackage().getEFactoryInstance()
										.create(eClass));
			}
		}
		// TODO : support structural features
		return null;
	}

	/**
	 * @generated
	 */
	public static ImageDescriptor getImageDescriptor(ENamedElement element) {
		String key = getImageRegistryKey(element);
		ImageDescriptor imageDescriptor = getImageRegistry().getDescriptor(key);
		if (imageDescriptor == null) {
			imageDescriptor = getProvidedImageDescriptor(element);
			if (imageDescriptor == null) {
				imageDescriptor = ImageDescriptor.getMissingImageDescriptor();
			}
			getImageRegistry().put(key, imageDescriptor);
		}
		return imageDescriptor;
	}

	/**
	 * @generated
	 */
	public static Image getImage(ENamedElement element) {
		String key = getImageRegistryKey(element);
		Image image = getImageRegistry().get(key);
		if (image == null) {
			ImageDescriptor imageDescriptor = getProvidedImageDescriptor(element);
			if (imageDescriptor == null) {
				imageDescriptor = ImageDescriptor.getMissingImageDescriptor();
			}
			getImageRegistry().put(key, imageDescriptor);
			image = getImageRegistry().get(key);
		}
		return image;
	}

	/**
	 * @generated
	 */
	public static ImageDescriptor getImageDescriptor(IAdaptable hint) {
		ENamedElement element = getElement(hint);
		if (element == null) {
			return null;
		}
		return getImageDescriptor(element);
	}

	/**
	 * @generated
	 */
	public static Image getImage(IAdaptable hint) {
		ENamedElement element = getElement(hint);
		if (element == null) {
			return null;
		}
		return getImage(element);
	}

	/**
	 * Returns 'type' of the ecore object associated with the hint.
	 * 
	 * @generated
	 */
	public static ENamedElement getElement(IAdaptable hint) {
		Object type = hint.getAdapter(IElementType.class);
		if (elements == null) {
			elements = new IdentityHashMap();

			elements.put(WorkflowType_79, ModelPackage.eINSTANCE
					.getWorkflowType());

			elements.put(PipelineType_1001, ModelPackage.eINSTANCE
					.getPipelineType());

			elements.put(ParallelType_1002, ModelPackage.eINSTANCE
					.getParallelType());

			elements.put(SequenceType_1003, ModelPackage.eINSTANCE
					.getSequenceType());

			elements.put(ActivityType_2001, ModelPackage.eINSTANCE
					.getActivityType());

			elements.put(InputsType_2002, ModelPackage.eINSTANCE
					.getInputsType());

			elements.put(InputType_2003, ModelPackage.eINSTANCE.getInputType());

			elements.put(InputStreamType_2004, ModelPackage.eINSTANCE
					.getInputStreamType());

			elements.put(DataType_2005, ModelPackage.eINSTANCE.getDataType());

			elements.put(OutputsType_2006, ModelPackage.eINSTANCE
					.getOutputsType());

			elements.put(OutputStreamType_2007, ModelPackage.eINSTANCE
					.getOutputStreamType());

			elements.put(WorkflowType_2008, ModelPackage.eINSTANCE
					.getWorkflowType());

			elements.put(PipelineType_2009, ModelPackage.eINSTANCE
					.getPipelineType());

			elements.put(ParallelType_2010, ModelPackage.eINSTANCE
					.getParallelType());

			elements.put(SequenceType_2011, ModelPackage.eINSTANCE
					.getSequenceType());

			elements.put(WorkflowType_2012, ModelPackage.eINSTANCE
					.getWorkflowType());

			elements.put(OutputStreamTypePipe_3001, ModelPackage.eINSTANCE
					.getOutputStreamType_Pipe());
		}
		return (ENamedElement) elements.get(type);
	}

	/**
	 * @generated
	 */
	private static IElementType getElementType(String id) {
		return ElementTypeRegistry.getInstance().getType(id);
	}

	/**
	 * @generated
	 */
	public static boolean isKnownElementType(IElementType elementType) {
		if (KNOWN_ELEMENT_TYPES == null) {
			KNOWN_ELEMENT_TYPES = new HashSet();
			KNOWN_ELEMENT_TYPES.add(WorkflowType_79);
			KNOWN_ELEMENT_TYPES.add(PipelineType_1001);
			KNOWN_ELEMENT_TYPES.add(ParallelType_1002);
			KNOWN_ELEMENT_TYPES.add(SequenceType_1003);
			KNOWN_ELEMENT_TYPES.add(ActivityType_2001);
			KNOWN_ELEMENT_TYPES.add(InputsType_2002);
			KNOWN_ELEMENT_TYPES.add(InputType_2003);
			KNOWN_ELEMENT_TYPES.add(InputStreamType_2004);
			KNOWN_ELEMENT_TYPES.add(DataType_2005);
			KNOWN_ELEMENT_TYPES.add(OutputsType_2006);
			KNOWN_ELEMENT_TYPES.add(OutputStreamType_2007);
			KNOWN_ELEMENT_TYPES.add(WorkflowType_2008);
			KNOWN_ELEMENT_TYPES.add(PipelineType_2009);
			KNOWN_ELEMENT_TYPES.add(ParallelType_2010);
			KNOWN_ELEMENT_TYPES.add(SequenceType_2011);
			KNOWN_ELEMENT_TYPES.add(WorkflowType_2012);
			KNOWN_ELEMENT_TYPES.add(OutputStreamTypePipe_3001);
		}
		return KNOWN_ELEMENT_TYPES.contains(elementType);
	}

}
